﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using wUniAppPCL.IO;
using wUniAppPCL.Loacalization;
using wUniAppPCL.MVVM;

namespace wUniAppPCL
{
  public class FilteredPatientsViewModel : BaseCollectionViewModel<Person>
  {
    public FilteredPatientsViewModel(PatientsViewModel patientsViewModel)
    {
      PVM = patientsViewModel;
          filter = new FilterHelper<Person>();
      filter.FilterChanged += filter_FilterChanged;
    }


    public void LoadFromSource()
    {
      Items.Clear();
      Items.AddRange(PVM.Items);
      OnPropertyChanged("Count");
    }

    public string Count
    {
      get { return Resources.Count + " " + Items.Count().ToString(); }
    }

    string fText = "";
    public void SetFilter(string text)
    {
      fText = text;
      IList<Person> filtered = Items;
      filter.ApplyFilter(text,  PVM.Items, ref filtered);
      OnPropertyChanged("Count");
    }
    PatientsViewModel PVM;

    void filter_FilterChanged(object sender, EventArgs e)
    {
      SetFilter(fText);
    }
    FilterHelper<Person> filter;
    public FilterHelper<Person> Filter
    {
      get
      {
        return filter;
      }
    }
  }
}
